Skip to main content

yRadio

yradio

Description

The yRadio is a clickable element with different optical styles, used to indicate its different states. The yRadio can be used to toggle a state or mirror a user selection where only one selection is possable. For example:

Basic Structure

In the following the basic structure of the yRadio shall be explained. For the general structure of a yComponent please visit the YBase-components basic-structure.

yradio

The yRadio as seen above contains a label and the radio.

Label

The label contains the text inside the button. It is on the right side of the component. By changing the inner padding of the button, the label gets moved too. You can find further explanation at the Label Property.

Radio

A radio button, often referred to as a radio bubble, is a graphical user interface element that allows the user to choose only one option from a set of predefined options. It appears as a small circle that, when selected, is filled or marked with a dot or check inside. Radio buttons are typically grouped together to form a radio group, ensuring that selecting one button will deselect any other previously selected button within the same group. This makes them ideal for presenting exclusive choices where only one selection is allowed, such as choosing a shipping option, selecting a gender, or picking a payment method.

Properties

Through its various properties the yRadio can be configured to suit your needs. The display below provides you with an overview of all the yRadio properties.

Properties can be changed directly through three methods:

  • Inside the Toolbar, which is positioned in your workarea next to your component where you need it. It shows the most important properties, thus providing a fast and efficient way to configure your component in the most basic way.
  • It may also occur in the Toolbar Extension, which is a seamless extension accesible as a dropdown item of the Toolbar. It extends the functionality of the Toolbar by providing advanced pickers for most used properties.
  • Inside the Detail Panel, which is located in the righthand drawer. Every property of a component can be configured here.
METAread more
--y-radio__component-id

The identifier of the component that is unique within a page.

--y-radio__component-type

The type of the component. For this component it is -radio.

--y-radio__name

The custom name of the component. It serves for better identification of the component.

--y-radio__version

The custom version of the Radio-component. This can be used to ensure that all components work well together.

--y-radio__core-theme

The CoreTheme, which will be apllied to the Radio. For further information on themes visit the themes page.

--y-radio__sub-theme

The subtheme subordinated to the previously specified CoreTheme, which will be apllied to the Radio. For further information on themes visit the themes page.

--y-radio__group-theme

The group theme is a further variation of the subtheme which is specified especially for variations of a component inside the subtheme. For further information on themes visit the Theme-Manager page.

DISPLAYread more
--y-radio__display

This property specifies the display behavior of the component. This can be be set to:

  • none
  • block
  • flex
  • inline
--y-radio__position

This property specifies the type of positioning method used for the component. This can be be set to:

  • static
  • relative
  • absolute
  • sticky
  • fixed
--y-radio__visible

This property can toggle the visibility of the component. The two modes are completely hidden and fully shown.

SIZEread more
--y-radio__min-width

The minimum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-radio__min-height

The minimum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %

The value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto

The value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-radio__max-width

The maximum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-radio__max-height

The maximum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-radio__flex

The flex property sets the length on flexible items. This sets the value in n-fold shares extrapolated to all other components with the flex display within the same container.

PLACEMENTread more
--y-radio__margin-top

This property creates a space around the component, outside of the top border. This can be set in percent or pixels.

--y-radio__margin-right

This property creates a space around the component, outside of the right border. This can be set in percent or pixels.

--y-radio__margin-bottom

This property creates a space around the component, outside of the bottom border. This can be set in percent or pixels.

--y-radio__margin-left

This property creates a space around the component, outside of the left border. This can be set in percent or pixels.

--y-radio__padding-top

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

--y-radio__padding-right

This property creates a space within the component, inside of the right border. This can be set in percent or pixels.

--y-radio__padding-bottom

This property creates a space within the component, inside of the bottom border. This can be set in percent or pixels.

--y-radio__padding-left

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

Usage

In this section you'll find a collection of application scenarios and examples that illustrate how to leverage the yRadio in ways that deviate from its standard behavior, as defined by yBase. This section aims to inspire and guide you through various possibilities, helping you to implement more complex or unique functionalities tailored to your specific needs. General properties that are universally applicable can be found in the yBase usage section.

Variations

Radio Elevated
Radio Flat
Radio Outlined
Radio Rounded
Radio Plain
genericsizeminWidth95px
genericsizemaxHeight30px
stylebackgroundbgColor__normal#44ddbb
styleshadowboxShadow__normal0 3px 6px 0 rgba(16, 18, 24, 0.2)
styleborderborderRadius8px
stylelabellabel__fontColor__normal#FFFFFF
styleradioradioOff__bgColortransparent
styleradioradioOff__borderColor#FFFFFF
styleradioradioOn__bgColortransparent
styleradioradioOn__borderColor#FFFFFF
styleradioradioOn__iconColor#FFFFFF

Radio Stylings

Radio Minimalistic
Radio Bold
Radio Luminous
genericsizemaxWidth120px
styleradioradio__circleAnimationColorOpacity0

Label Variations

Radio Label Left
Radio Label Right
Radio Label Both
genericsizeminWidth'auto'
genericsizemaxWidthnone
stylelabelleftLabel'left'

Dynamic Value Assignment

The yRadio component is designed to facilitate dynamic user interactions within your application. It achieves this through two primary properties found within the "style" > "radio" category, value and comparisonVal.

Value Property

The value property is intended to be set externally, either by user action or programmatically via JavaScript. This property represents the current state or selection of the yRadio component.

Via Javascript:

Button EvtClicked
// function onButton_1_EvtClicked (apiObject, component, eventData)
const shipingMethod = "LKW";
const radioComponent = apiObject.ui.getObject(1, "y-radio");
radioComponent.set("style", "radio", "value", shipingMethod);
//}

In this snippet, yourDesiredValue is the actual value that you want the yRadio to hold, which will reflect the user's selection. Alternatively, yRadio can obtain its value through a SourceLink. This method establishes a connection between yRadio and another component. The value received through the SourceLink is then compared against the comparisonVal to determine the radio button's state. The value can be coupled to a Clipboard value via the SourceLink Picker.

Via SourceLink:

  1. Create a yRadio component in your application.
  2. Create a yInput component in your application.
  3. Select the created yRadio and open the Detail Panel.
  4. Within these settings, proceed to the "Links" section and open "Value".
  5. Create a new sourceLink -> select the yInput you just created and choose input-string as an event.

In this example you should find a way to demand either by mask/validation or javascript to make sure the input-string is represented as a radio-value.

ComparisonVal Property

The comparisonVal serves as a unique identifier for a yRadio component within a group of similar radio buttons. To create a set of mutually exclusive selections — where choosing one option deselects the others — multiple yRadio components can share the same comparisonVal.

For instance, if you have a group of radio buttons for selecting a shipping method, each radio button's comparisonVal might be set to "shippingMethod". The one whose value matches the comparisonVal will be marked as selected:

yButton:EvtClicked
// function onButton_1_EvtClicked (apiObject, component, eventData)
const shipingMethod = "SHIP";
const radioComponent = apiObject.ui.getObject(1, "y-radio");
radioComponent.set("style", "radio", "comparisonVal", shipingMethod);
//}

The Comparisonval should only seldomly be changed via javascript.

Coupling and Selection State

When you have multiple radio buttons with the same comparisonVal, they are effectively coupled. The selection state (true or false) of these yRadio components is determined by comparing their value with their comparisonVal. When the value matches the comparisonVal, that particular radio button is selected (its state is true). If they don't match, the radio button remains unselected (its state is false).

This mechanism ensures that within a set of yRadio components with the same purpose, only the one with a matching value will be selected, enforcing the rule that only one option can be chosen at a time in a radio group.

By leveraging the value and comparisonVal properties, yRadio components can be effectively used to create a responsive and intuitive selection interface within your application.

Real Life Use Cases

Payment for a shop

This example provides the code to get the selected Payment-Method from radio buttons without the usage of a sourceLink for an external radio value. When a button is clicked the selected payment method will be fetched.

Button EvtClicked
// function onButton_1_EvtClicked (apiObject, component, eventData)
// Assume we have 3 radio buttons for payment methods: "Credit Card", "PayPal", "Bank Transfer"
// Each radio button has a unique ID

let selectedMethod;
const paymentMethods = [
{
name: "Credit Card",
radioId: 4,
},
{
name: "PayPal",
radioId: 5,
},
{
name: "Bank Transfer",
radioId: 6,
},
];

paymentMethods.forEach((method) => {
const radioButton = apiObject.ui.getObject(method.radioId, "y-radio");
const selectedValue = radioButton.get("style", "radio", "value");
const comparisonValue = radioButton.get("style", "radio", "comparisonValue");
const isSelected = selectedValue == comparisonValue;

if (isSelected) {
selectedMethod = method.name;
console.log(`Selected payment method: ${method.name}`);
}
});

if (!selectedMethod) {
alert("Please select a payment method.");
return false;
}

return true;
//}

Displaymodes

In this example three radios with the keys depicted in displayModes variables are needed. The following function has to be included in each of those radios as the 'EvtClicked'-Function.

Radio EvtClicked
// function onRadio_1_EvtClicked (apiObject, component, eventData)
// Function to toggle UI elements based on the selected display mode using YRadio
const displayModes = {
BasicView: ["basicElement1", "basicElement2"], // List of elements to be shown in Basic View
AdvancedView: ["advancedElement1", "advancedElement2"], // List of elements for Advanced View
ExpertView: ["expertElement1", "expertElement2"], // List of elements for Expert View
};

// Assume the radio buttons have IDs that match the display modes
const selectedMode = component.get("style", "radio", "value");

// Hide all elements first
Object.values(displayModes)
.flat()
.forEach((elementId) => {
const element = apiObject.ui.getObject(elementId);
element.set("generic", "display", "visible", "none");
});

// Show elements for the selected mode
if (displayModes[selectedMode]) {
displayModes[selectedMode].forEach((elementId) => {
const element = apiObject.ui.getObject(elementId);
element.set("generic", "display", "visible", "block");
});
console.log(`Display mode set to: ${selectedMode}`);
} else {
console.error("Selected mode is not recognized:", selectedMode);
}
//}

Special Picker

There is a special picker for the yRadio in the Toolbar as a Toolbar Extension which will be used to link the component to a logic of 2 or more other components. This is a kind of SourceLink Picker, similar to other SourceLink Pickers to be found in other components.